<div class="card">
    <div class="card-block">
        <h6>修改登陆密码</h6>
    </div>
    <div class="card-block">
        <form id="form1">
            <div class="form-group col-xl-6">
                <label for="pass">原密码</label>
                <input type="password" class="form-control" id="pass1" name="pass1" value="">
            </div>
            <div class="form-group col-xl-6">
                <label for="pass">新密码</label>
                <input type="password" class="form-control" id="pass2" name="pass2" value="">
            </div>
            <div class="form-group col-xl-6">
                <label for="pass">确认新密码</label>
                <input type="password" class="form-control" id="pass3" name="pass3" value="">
            </div>
            <button type="submit" class="btn btn-primary"><i class="fa fa-save" /> 保存</button>
        </form>
    </div>
</div>
<script type="text/javascript" src="/static/jquery/jquery.md5.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#form1").submit(function () {
            var pass1 = $("#pass1").val();
            var pass2 = $("#pass2").val();
            var pass3 = $("#pass3").val();

            if(pass1.length < 4) {
                $("#pass1").addClass("input-error");
                alert("新密码最少为4位！");
                return false;
            }
            if(pass2.length < 4 || pass3.length < 4) {
                $("#pass2").addClass("input-error");
                $("#pass3").addClass("input-error");
                alert("新密码最少为4位！");
                return false;
            }
            if(pass2 != pass3) {
                $("#pass2").addClass("input-error");
                $("#pass3").addClass("input-error");
                alert("新密码和确认密码不一样，请确认后重新输入！");
                return false;
            }

            $.ajax({
                url: "?m=personal&a=chnpwd_save",
                type: "POST",
                data: { pass1: $.md5(pass1), pass2: $.md5(pass2), pass3: $.md5(pass3) },
                dataType: "json",
                error: function(xhr,textStatus){
                    alert(textStatus);
                },
                success: function (data,textStatus,jqXHR) {
                    if(data.status == "error") {
                        alert(data.msg);
                    } else {
                        alert("修改密码完成，请重新登陆！");
                        _refresh_page();
                    }
                }
            });
            return false;
        });
    });

</script>